package com.xy.biz.uc.event;

import com.xy.biz.uc.client.TeamEventBusClient;
import com.xy.biz.uc.domain.resp.GetTeamResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;

/**
 * @author Greekn Zhang
 * @date 2021/6/3 11:36
 * @description 事件总线
 */
@Service
public class TeamEventBus implements TeamEventBusClient {
    private List<Consumer<Long>> afterTeamChangeHandlerList = new CopyOnWriteArrayList<>();

    @Override
    @Transactional
    public void addDocumentEditHandler(Consumer<Long> handler) {
        afterTeamChangeHandlerList.add(handler);
    }

    @Override
    @Transactional
    public void fireDocumentEditHandler(Long teamId) {
        afterTeamChangeHandlerList.forEach(e -> e.accept(teamId));
    }
}
